package com.jacobson.huobi.common.constants

object PriorityNumConstant {

    // (value & mask）>> offset

    //优先级{num}的计数蒙版
    const val MASK_SATISFY_01 = 0x00000000FFL // 255
    const val MASK_SATISFY_02 = 0x000000FF00L // 65280
    const val MASK_SATISFY_03 = 0x0000FF0000L // 16711680
    const val MASK_SATISFY_04 = 0x00FF000000L // 4278190080
    const val MASK_SATISFY_05 = 0xFF00000000L // 1095216660480

    //优先级{num}的偏移
    const val OFFSET_SATISFY_01 = 0
    const val OFFSET_SATISFY_02 = 8
    const val OFFSET_SATISFY_03 = 16
    const val OFFSET_SATISFY_04 = 24
    const val OFFSET_SATISFY_05 = 32


    fun getPriorityNumByLevel(type: Int, value: Long): Int {
        return when(type){
            1 -> ((value and MASK_SATISFY_01) shr(OFFSET_SATISFY_01)).toInt()
            2 -> ((value and MASK_SATISFY_02) shr(OFFSET_SATISFY_02)).toInt()
            3 -> ((value and MASK_SATISFY_03) shr(OFFSET_SATISFY_03)).toInt()
            4 -> ((value and MASK_SATISFY_04) shr(OFFSET_SATISFY_04)).toInt()
            5 -> ((value and MASK_SATISFY_05) shr(OFFSET_SATISFY_05)).toInt()
            else -> 999
        }
    }

}